<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="jmz/css/animate.css" rel="stylesheet">
    <link href="jmz/css/login.css" rel="stylesheet">

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/layer.js"></script>
    <script src="jmz/js/global.js" charset="utf-8"></script>

    <script>
        code();

        function code() {
            $('.verify').attr('src', '/verify?t=' + Date.parse(new Date()));
        }
    </script>

</head>

<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-12">
            <form>
                <div>
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到我的后台</p>
                    <input type="text" class="form-control uname" name="username" placeholder="用户名"/>
                    <input type="password" class="form-control pword m-b" name='password' placeholder="密码"/>
                </div>
                <div class="btn btn-success btn-block submit">登录</div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    function callback(jsonstr) {
        var data = jQuery.parseJSON(jsonstr)

        localStorage.setItem('cdce_serivce_token', data.token);
        localStorage.setItem('cdce_serivce_uname', $('input[name="username"]').val());
        localStorage.setItem('cdce_serivce_pwd', $('input[name="password"]').val());

        layer.msg('登录成功');
        location.href = '/index';
    }

    function errcallback(status) {
        console.log(status);
        layer.msg("用户名或密码有误");
    }

    $('body').on('click', '.submit', function () {
        var uname = $('input[name="username"]').val();
        var pwd = $('input[name="password"]').val();
        if (uname && pwd) {
            var data = {'username': uname, 'password': pwd};
            post('http://127.0.0.1:8081/login', JSON.stringify(data), callback, errcallback);
        } else {
            layer.msg('请填写完成信息');
        }
    })

    $('input[name="username"]').val(localStorage.getItem('cdce_serivce_uname'));
    $('input[name="password"]').val(localStorage.getItem('cdce_serivce_pwd'));

</script>
</body>

</html>